package com.ql.service.sbglService.impl;

import com.ql.dao.sheBeiGuanLi.SBKCMapper;
import com.ql.pojo.sheBeiGuanLi.SheBeiKuCun;
import com.ql.service.sbglService.SBCKService;
import com.ql.utils.PageHelper;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service("sbckService")
public class SBCKServiceImpl implements SBCKService {
    private static final Logger logger=Logger.getLogger(SBCKServiceImpl.class);
    @Resource
    private SBKCMapper sbkcMapper;
    //获取库存所有信息
    public List<SheBeiKuCun> getAllSheBeiKuCun(PageHelper ph,String xzId, String zt,int keshi,String mohuName) {
        List<SheBeiKuCun> sheBeiKuCunList=new ArrayList<SheBeiKuCun>();
        try {
            //add:更新总条数
            ph.setTotalCount(sbkcMapper.qryCount(xzId,zt,keshi,mohuName));
            sheBeiKuCunList=sbkcMapper.qryAll((ph.getCurrentPageNo()-1)*ph.getPageSize(),ph.getPageSize(),xzId,zt,keshi,mohuName);
            if(sheBeiKuCunList.size() <=0){
                logger.debug("SBCKServiceImpl.getAllSheBeiKuCun 查询为空！");
            }else{
                logger.debug("SBCKServiceImpl.getAllSheBeiKuCun 查询成功！");
            }
        } catch (Exception e) {
//            e.printStackTrace();
            logger.debug("SBCKServiceImpl.getAllSheBeiKuCun 查询异常！》》》》》》"+e.getMessage());
        }
        return sheBeiKuCunList;
    }
    //单个删除
    @Override
    public boolean removeSBCK(int sId) {
        int row=0;
        try {
            row=sbkcMapper.del(sId);
            if(row !=1){
                logger.debug("SBCKServiceImpl.removeSBCK 删除库存信息失败！");
                return false;
            }else{
                logger.debug("SBCKServiceImpl.removeSBCK 删除库存信息成功！");
                return true;
            }
        } catch (Exception e) {
            logger.error("SBCKServiceImpl.removeSBCK 删除库存信息异常》》》"+e.getMessage());
            return false;
        }
    }
    //批量删除
    @Override
    public boolean deleteBatch(List<Integer> list) {
        boolean result = false;//默认删除失败
        try {
            int x = sbkcMapper.delBatch(list);//x!=0就删除成功了
            if(x!=0){
                result = true;
            }
        } catch (Exception e) {
//            e.printStackTrace();
            logger.error("SBCKServiceImpl.deleteBatch删除异常！"+e.getMessage());
        }
        return result;
    }
    //获取id查询库存信息
    @Override
    public SheBeiKuCun getKCById(String sId){
        SheBeiKuCun sheBeiKuCun=null;
        try{
            sheBeiKuCun=sbkcMapper.qryById(sId);
        }catch (Exception e){
            logger.error("SBCKServiceImpl.getKCById查询异常！"+e.getMessage());
            sheBeiKuCun=new SheBeiKuCun();
        }
        return sheBeiKuCun;
    }
    //新增库存
    @Override
    public boolean addNewSBKC(SheBeiKuCun sheBeiKuCun) {
        int row=0;
        try {
            row=sbkcMapper.save(sheBeiKuCun);
            if(row==1){
                logger.debug("SBCKServiceImpl.addNewSBKC新增库存成功！");
                return true;
            }else {
                logger.debug("SBCKServiceImpl.addNewSBKC新增库存失败！");
                return false;
            }
        } catch (Exception e) {
//            e.printStackTrace();
            logger.error("SBCKServiceImpl.addNewSBKC新增库存异常！"+e.getMessage());
            return false;
        }
    }
    //修改库存
    @Override
    public boolean updateSBKC(SheBeiKuCun sheBeiKuCun) {
        boolean updateSBKC=false;
        try {
            int row=sbkcMapper.modify(sheBeiKuCun);
            if(row==1){
                logger.debug("SBCKServiceImpl.updateSBKC修改库存成功！");
                updateSBKC=true;
            }else {
                logger.debug("SBCKServiceImpl.updateSBKC修改库存失败！");
                updateSBKC=false;
            }
        } catch (Exception e) {
//            e.printStackTrace();
            logger.error("SBCKServiceImpl.updateSBKC修改库存异常！"+e.getMessage());
            updateSBKC=false;
        }
        return updateSBKC;
    }

}
